﻿using System.Linq;
using Microsoft.SharePoint.Administration;

namespace System.Modules.SharePoint.Extensions
{
    /// <summary>
    /// SP Job Definition Collection Extensions
    /// </summary>
    public static class SPJobDefinitionCollectionExtensions
    {
        #region Delete
        /// <summary>
        /// This Method deletes a timer job from the collection.
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="jobName"></param>
        public static void Delete(this SPJobDefinitionCollection collection, string jobName)
        {
            if (collection != null)
            {
                SPJobDefinition job = collection.FirstOrDefault(match => match.Name.Equals(jobName));
                if (job != null)
                {
                    job.Delete();
                }
            }
        }
        #endregion
    }
}